<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\AddNodeRequest;
use App\Models\Node;
use Illuminate\Http\Request;

class NodeController extends BaseController
{
    //权限列表
    public function index()
    {
        //层级显示数据
        $data=treeLevel(Node::get()->toArray());
        return view('admin.node.index',compact('data'));
    }
    //权限添加显示
    public function create()
    {
        //获取顶级菜单
        $data=Node::where('pid',0)->where('is_menu','1')->get();
        return view('admin.node.create',compact('data'));
    }

    //表单验证  扩展请求类中完成验证,使用依赖注入引入
    public function store(AddNodeRequest $request)
    {
        //入库
        Node::create($request->except('_token'));
        return redirect(route('admin.node.index'))->with('success','添加权限成功');

    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Node  $node
     * @return \Illuminate\Http\Response
     */
    public function show(Node $node)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Node  $node
     * @return \Illuminate\Http\Response
     */
    public function edit(Node $node)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Node  $node
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Node $node)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Node  $node
     * @return \Illuminate\Http\Response
     */
    public function destroy(Node $node)
    {
        //
    }
}
